<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $saltPassword
 * @property string $nama
 * @property string $email
 * @property integer $agama_id
 * @property string $asalDaerah
 * @property integer $angkatan_id
 * @property string $penempatan
 * @property string $foto
 * @property integer $levelUser_id
 *
 * The followings are the available model relations:
 * @property Absensi[] $absensis
 * @property Amanah[] $amanahs
 * @property Kegiatan[] $kegiatans
 * @property Keuangan[] $keuangans
 * @property Mediasosial[] $mediasosials
 * @property Nomorhp[] $nomorhps
 * @property Rapat[] $rapats
 * @property Riwayatdivisi[] $riwayatdivisis
 * @property Riwayatkelas[] $riwayatkelases
 * @property Runningtext[] $runningtexts
 * @property Angkatan $angkatan
 * @property Agama $agama
 * @property Leveluser $levelUser
 */
class UserUpdateProfil extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username, nama, agama_id, asalDaerah, angkatan_id', 'required'),
			array('agama_id, angkatan_id, levelUser_id', 'numerical', 'integerOnly'=>true),
			array('nama, penempatan', 'length', 'max'=>50),
			array('email', 'length', 'max'=>255),
			array('email', 'email', 'checkMX' => true),
			array('asalDaerah', 'length', 'max'=>1000),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, nama, email, agama_id, asalDaerah, angkatan_id, penempatan, levelUser_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'absensis' => array(self::HAS_MANY, 'Absensi', 'user_id'),
			'amanahs' => array(self::HAS_MANY, 'Amanah', 'user_id'),
			'kegiatans' => array(self::HAS_MANY, 'Kegiatan', 'user_id'),
			'keuangans' => array(self::HAS_MANY, 'Keuangan', 'user_id'),
			'mediasosials' => array(self::HAS_MANY, 'Mediasosial', 'user_id'),
			'nomorhps' => array(self::HAS_MANY, 'Nomorhp', 'user_id'),
			'rapats' => array(self::HAS_MANY, 'Rapat', 'user_id'),
			'riwayatdivisis' => array(self::HAS_MANY, 'Riwayatdivisi', 'user_id'),
			'riwayatkelases' => array(self::HAS_MANY, 'Riwayatkelas', 'user_id'),
			'runningtexts' => array(self::HAS_MANY, 'Runningtext', 'user_id'),
			'angkatan' => array(self::BELONGS_TO, 'Angkatan', 'angkatan_id'),
			'agama' => array(self::BELONGS_TO, 'Agama', 'agama_id'),
			'levelUser' => array(self::BELONGS_TO, 'Leveluser', 'levelUser_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nama' => 'Nama Lengkap',
			'email' => 'Email Aktif',
			'agama_id' => 'Agama',
			'asalDaerah' => 'Asal Daerah',
			'angkatan_id' => 'Angkatan',
			'penempatan' => 'Penempatan',
			'levelUser_id' => 'Level User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nama',$this->nama,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('agama_id',$this->agama_id);
		$criteria->compare('asalDaerah',$this->asalDaerah,true);
		$criteria->compare('angkatan_id',$this->angkatan_id);
		$criteria->compare('penempatan',$this->penempatan,true);
		$criteria->compare('levelUser_id',$this->levelUser_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	  public function behaviors()
		{
			return array('ESaveRelatedBehavior' => array(
					'class' => 'application.components.ESaveRelatedBehavior')
			);
		}
}